package src.multithreading;

public class StateVisionTest {
    public static void main(String[] args) {
        Thread thread = new Thread(()->{
            for (int i = 0; i < 5; i++) {
                System.out.println("output 1.");
                try {
                    System.out.println("output 1.");
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("output 2.");
        });

        Thread.State state = thread.getState();
        System.out.println("线程状态："+state);//new

        thread.start();
        state = thread.getState();
        System.out.println("线程状态："+state);//run

        while(state!= Thread.State.TERMINATED){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            state = thread.getState();//更新线程状态
            System.out.println("线程状态："+state);
        }
    }
}
